<template>
  <div class="nav-header">
    <i
      :class="isFold ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
      class="fold-menu"
      @click="handleFoldClick"
    ></i>
    <div class="content">
      <div><HyBreadcrumb :breadcrumbs="breadcrumb"></HyBreadcrumb></div>
      <div><user-info></user-info></div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue'
import UserInfo from './user-info.vue'
import HyBreadcrumb from '@/base-ui/breadcrumb'
import { pathMapBreadcrumbs } from '@/utils/map-menus' //调用封装方法
import { useStore } from '@/store'
import { useRoute } from 'vue-router'

export default defineComponent({
  emits: ['foldChange'],
  components: { UserInfo, HyBreadcrumb },
  setup(props, { emit }) {
    const isFold = ref(false)
    // 点击菜单
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }
    // 面包屑数据 {name:xxx,path:xxx}
    const store = useStore()
    const route = useRoute()
    const breadcrumb = computed(() => {
      const userMenus = store.state.login.userMenus
      const currentPath = route.path
      return pathMapBreadcrumbs(userMenus, currentPath)
    })
    return { isFold, handleFoldClick, breadcrumb }
  },
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    display: flex;
    padding: 0 20px;
    flex: 1;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
